package com.jeecg.demo.api;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeecg.demo.entity.AppPrivacypolicyEntity;
import com.jeecg.demo.service.AppPrivacypolicyServiceI;

/**
 * 隐私政策
 * @author Administrator
 *
 */
@Api(value = "appPrivacyPolicy", description = "隐私政策", tags = "appPrivacyPolicy")
@Controller
@RequestMapping("/appPrivacyPolicy")
public class AppPrivacyPolicy {
	@Autowired
	private AppPrivacypolicyServiceI appPrivacypolicyService;
	
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "隐私政策列表", produces = "application/json")
	public ResponseMessage<List<AppPrivacypolicyEntity>> list() {
		List<AppPrivacypolicyEntity> list=appPrivacypolicyService.getList();
		return Result.success(list);
	}
	
	@RequestMapping(value = "/getDetail/{id}", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "隐私政策详情", produces = "application/json")
	public ResponseMessage<Map<String,Object>> getDetail(@ApiParam(required=true,name="id",value="ID")@PathVariable("id") String id) {
		AppPrivacypolicyEntity  appPrivacyPolicy=appPrivacypolicyService.getDetail(Integer.parseInt(id));
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("data", appPrivacyPolicy);
		try {
			map.put("policyContent", new String(appPrivacyPolicy.getPolicyContent(),"GBK"));
			//map.put("policyDesc", new String(appPrivacyPolicy.getPolicyDesc(),"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return Result.success(map);
	}
	
	@RequestMapping(value = "/getNewPolicyDesc", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "获取最新的隐私政策详情", produces = "application/json")
	public ResponseMessage<Map<String,Object>> getNewPolicyDesc() {
		AppPrivacypolicyEntity  appPrivacyPolicy=appPrivacypolicyService.getNewPolicyDesc();
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("data", appPrivacyPolicy);
		try {
			//map.put("policyContent", new String(appPrivacyPolicy.getPolicyContent(),"UTF-8"));
			map.put("policyDesc", new String(appPrivacyPolicy.getPolicyDesc(),"GBK"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return Result.success(map);
	}
}
